/*
 * @Author: yyyyjinying
 * @Date: 2024-07-31 22:50:32
 * @LastEditTime: 2024-07-31 22:50:35
 * @LastEditors: yyyyjinying
 * @Description:
 * @FilePath: /heima-shop/src/stores/modules/address.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */
import type { AddressItem } from '@/types/address'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAddressStore = defineStore('address', () => {
  const selectedAddress = ref<AddressItem | null>(null)

  const deliveryPrice = ref(0)

  const getDeliveryPrice = () => {
    return deliveryPrice.value
  }

  const setDeliveryPrice = (val: number) => {
    deliveryPrice.value = val
  }
  const changeSelectedAddress = (val: AddressItem) => {
    selectedAddress.value = val
  }

  const getAddress = () => {
    return selectedAddress.value as AddressItem
  }

  return { selectedAddress, getDeliveryPrice, setDeliveryPrice, getAddress, changeSelectedAddress }
})
